﻿Imports System.ComponentModel
Imports DevExpress.XtraEditors
Imports DevExpress.XtraBars.Helpers
Imports DevExpress.Skins
Imports DevExpress.LookAndFeel
Imports DevExpress.UserSkins
Imports System.Data

Public Class Admin
    Sub New()
        InitSkins()
        InitializeComponent()
        Me.InitSkinGallery()

    End Sub
    Sub InitSkins()
        DevExpress.Skins.SkinManager.EnableFormSkins()
        DevExpress.UserSkins.BonusSkins.Register()
        UserLookAndFeel.Default.SetSkinStyle("DevExpress Style")

    End Sub
    Private Sub InitSkinGallery()
        SkinHelper.InitSkinGallery(rgbiSkins, True)
    End Sub
    Dim gridDataList As New BindingList(Of Person)


    Private Sub Admin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        gvNhanVien_load()
        Combobox_load()
        gvKhachHang_load()
        gvNguyenLieu_load()
        gvban_load()
    End Sub


    Public Sub Combobox_load()
        Dim bus1 As NhanVienBUS = New NhanVienBUS()
        cbxChucVu.DataSource = bus1.GetTable("select * from ChucVu")
        cbxChucVu.DisplayMember = "TenChucVu"
        cbxChucVu.ValueMember = "MaChucVu"

        Dim bus2 As KhachHangBUS = New KhachHangBUS()
        cbxLoaiKhachHang.DataSource = bus2.GetTable("select * from LoaiKhachHang")
        cbxLoaiKhachHang.DisplayMember = "TenLoai"
        cbxLoaiKhachHang.ValueMember = "MaLoai"

        Dim bus3 As BanBUS = New BanBUS()
        cbxNhanVienBan.DataSource = bus3.GetTable("select * from NhanVien")
        cbxNhanVienBan.DisplayMember = "HoTen"
        cbxNhanVienBan.ValueMember = "MaNhanVien"
        cbxKhachHangBan.DataSource = bus3.GetTable("select * from KhachHang")
        cbxKhachHangBan.DisplayMember = "HoTen"
        cbxKhachHangBan.ValueMember = "MaKhachHang"
        cbxTinhTrangBan.DataSource = bus3.GetTable("select * from TinhTrang")
        cbxTinhTrangBan.DisplayMember = "TenTinhTrang"
        cbxTinhTrangBan.ValueMember = "MaTinhTrang"
        cbxThucDon.DataSource = bus3.GetTable("select * from NguyenLieu")
        cbxThucDon.DisplayMember = "TenNguyenLieu"
        cbxThucDon.ValueMember = "MaNguyenLieu"
    End Sub

    'gv nhan vien
    Public Sub gvNhanVien_load()
        Dim bus As NhanVienBUS = New NhanVienBUS()
        gvNhanVien.DataSource = bus.GetTable("select * from NhanVien")
    End Sub

    Private Sub btnThemNhanVien_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemNhanVien.Click
        Dim temp As NhanVienDTO = New NhanVienDTO()
        Dim bus As NhanVienBUS = New NhanVienBUS()
        temp.HoTen = txtHoTenNhanVien.Text
        temp.QueQuan = txtQueNhanVien.Text
        temp.CMND = txtCMNDNhanVien.Text
        temp.NgaySinh = dtpNgaySinh.Value.Date
        temp.ChucVu = cbxChucVu.SelectedValue.ToString()
        bus.Insert(temp)
        gvNhanVien_load()
    End Sub

    Private Sub btnXoaNhanVien_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaNhanVien.Click
        Dim bus As NhanVienBUS = New NhanVienBUS()
        Dim tmp As NhanVienDTO = New NhanVienDTO()
        tmp.MaNhanVien = lbMaNhanVien.Text
        bus.Delete(tmp)
        gvNhanVien_load()
    End Sub

    Private Sub btnSuaNhanVien_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSuaNhanVien.Click
        Dim temp As NhanVienDTO = New NhanVienDTO()
        Dim bus As NhanVienBUS = New NhanVienBUS()
        temp.MaNhanVien = lbMaNhanVien.Text
        temp.HoTen = txtHoTenNhanVien.Text
        temp.QueQuan = txtQueNhanVien.Text
        temp.CMND = txtCMNDNhanVien.Text
        temp.NgaySinh = dtpNgaySinh.Value.Date
        temp.ChucVu = cbxChucVu.SelectedValue.ToString()
        bus.Update(temp)
        gvNhanVien_load()
    End Sub

    Private Sub gvNhanVien_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gvNhanVien.SelectionChanged
        Dim bus As NhanVienBUS = New NhanVienBUS()
        Try
            If (gvNhanVien.SelectedRows.Count = 0) Then
                Return
            End If
            lbMaNhanVien.Text = gvNhanVien.CurrentRow.Cells(0).Value.ToString()
            txtHoTenNhanVien.Text = gvNhanVien.CurrentRow.Cells(1).Value.ToString()
            txtQueNhanVien.Text = gvNhanVien.CurrentRow.Cells(2).Value.ToString()
            cbxChucVu.Text = bus.GetValue("select TenChucVu from ChucVu where MaChucVu=" + gvNhanVien.CurrentRow.Cells(3).Value.ToString())
            dtpNgaySinh.Value = gvNhanVien.CurrentRow.Cells(4).Value
            txtCMNDNhanVien.Text = gvNhanVien.CurrentRow.Cells(5).Value
        Catch

        End Try
    End Sub


    ''GV Khach Hang
    Public Sub gvKhachHang_load()
        Dim bus As KhachHangBUS = New KhachHangBUS()
        gvKhachHang.DataSource = bus.GetTable("select * from KhachHang")
    End Sub

    Private Sub gvKhachHang_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gvKhachHang.SelectionChanged
        Dim bus As KhachHangBUS = New KhachHangBUS()
        Try
            If (gvKhachHang.SelectedRows.Count = 0) Then
                Return
            End If
            lvMaKhachHang.Text = gvKhachHang.CurrentRow.Cells(0).Value.ToString()
            txtHoTenKhachHang.Text = gvKhachHang.CurrentRow.Cells(1).Value.ToString()
            txtQueNhanVien.Text = gvKhachHang.CurrentRow.Cells(2).Value.ToString()
            cbxLoaiKhachHang.Text = bus.GetValue("select TenLoai from LoaiKhachHang where MaLoai=" + gvKhachHang.CurrentRow.Cells(3).Value.ToString())
            dtpNgaySinhKhachHang.Value = gvKhachHang.CurrentRow.Cells(4).Value
            txtCMNDKhachHang.Text = gvKhachHang.CurrentRow.Cells(5).Value
        Catch

        End Try
    End Sub

    Private Sub btnThemKhachHang_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemKhachHang.Click
        Dim temp As KhachHangDTO = New KhachHangDTO()
        Dim bus As KhachHangBUS = New KhachHangBUS()
        temp.HoTen = txtHoTenKhachHang.Text
        temp.QueQuan = txtQueKhachHang.Text
        temp.CMND = txtCMNDKhachHang.Text
        temp.NgaySinh = dtpNgaySinhKhachHang.Value.Date
        temp.MaLoai = cbxLoaiKhachHang.SelectedValue.ToString()
        bus.Insert(temp)
        gvKhachHang_load()
    End Sub

    Private Sub btnXoaKhachHang_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaKhachHang.Click
        Dim bus As KhachHangBUS = New KhachHangBUS()
        Dim tmp As KhachHangDTO = New KhachHangDTO()
        tmp.MaKhachHang = lvMaKhachHang.Text
        bus.Delete(tmp)
        gvKhachHang_load()
    End Sub

    Private Sub btnCapNhatKhachHang_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapNhatKhachHang.Click
        Dim temp As KhachHangDTO = New KhachHangDTO()
        Dim bus As KhachHangBUS = New KhachHangBUS()
        temp.HoTen = txtHoTenKhachHang.Text
        temp.QueQuan = txtQueKhachHang.Text
        temp.CMND = txtCMNDKhachHang.Text
        temp.NgaySinh = dtpNgaySinhKhachHang.Value.Date
        temp.MaLoai = cbxLoaiKhachHang.SelectedValue.ToString()
        bus.Update(temp)
        gvKhachHang_load()
    End Sub


    ''Nguyen Lieu
    Public Sub gvNguyenLieu_load()
        Dim bus As NguyenLieuBUS = New NguyenLieuBUS()
        gvNguyenLieu.DataSource = bus.GetTable("select * from NguyenLieu")

    End Sub

    Private Sub gvNguyenLieu_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gvNguyenLieu.SelectionChanged
        Dim bus As NguyenLieuBUS = New NguyenLieuBUS()
        Try
            If (gvNguyenLieu.SelectedRows.Count = 0) Then
                Return
            End If
            lbMaNguyenLieu.Text = gvNguyenLieu.CurrentRow.Cells(0).Value.ToString()
            txtTenNguyenLieu.Text = gvNguyenLieu.CurrentRow.Cells(1).Value.ToString()
            txtNguonGocNguyenLieu.Text = gvNguyenLieu.CurrentRow.Cells(2).Value.ToString()
            txtSoLuongNguyenLieu.Text = gvNguyenLieu.CurrentRow.Cells(3).Value.ToString()
            dtpNgayNhapNguyenLieu.Value = gvNguyenLieu.CurrentRow.Cells(4).Value
            txtGiaNguyenLieu.Text = gvNguyenLieu.CurrentRow.Cells(5).Value
        Catch

        End Try
    End Sub

    Private Sub btnThemNguyenLieu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemNguyenLieu.Click
        Dim temp As NguyenLieuDTO = New NguyenLieuDTO()
        Dim bus As NguyenLieuBUS = New NguyenLieuBUS()
        temp.TenNguyenLieu = txtTenNguyenLieu.Text
        temp.NguonGoc = txtNguonGocNguyenLieu.Text
        temp.SoLuong = txtSoLuongNguyenLieu.Text
        temp.NgayNhap = dtpNgayNhapNguyenLieu.Value.Date
        temp.Gia = txtGiaNguyenLieu.Text
        bus.Insert(temp)
        gvNguyenLieu_load()
    End Sub


    Private Sub btnXoaNguyenLieu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaNguyenLieu.Click
        Dim bus As NguyenLieuBUS = New NguyenLieuBUS()
        Dim tmp As NguyenLieuDTO = New NguyenLieuDTO()
        tmp.MaNguyenLieu = lbMaNguyenLieu.Text
        bus.Delete(tmp)
        gvNguyenLieu_load()
    End Sub

    ''Bàn
    Public Sub gvBan_load()
        Dim bus As BanBUS = New BanBUS
        gvBan.DataSource = bus.GetTable("select * from Ban")
    End Sub

    Private Sub gvBan_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gvBan.SelectionChanged
        Dim bus As BanBUS = New BanBUS()
        Try
            If (gvBan.SelectedRows.Count = 0) Then
                Return
            End If
            lbMaBan.Text = gvBan.CurrentRow.Cells(0).Value.ToString()
            cbxNhanVienBan.Text = bus.GetValue("select HoTen from NhanVien where MaNhanVien=" + gvBan.CurrentRow.Cells(1).Value.ToString())
            cbxKhachHangBan.Text = bus.GetValue("select HoTen from KhachHang where MaKhachHang=" + gvBan.CurrentRow.Cells(2).Value.ToString())
            'cbxThucDon.Text = bus.GetValue("select TenNguyenLieu from NguyenLieu where MaNguyenLieu=" + gvBan.CurrentRow.Cells(3).Value.ToString())
            dtpNgayGioBan.Value = gvBan.CurrentRow.Cells(4).Value
            lbTongTienBan.Text = gvBan.CurrentRow.Cells(5).Value
            cbxTinhTrangBan.Text = bus.GetValue("select TenTinhTrang from TinhTrang where MaTinhTrang =" + gvBan.CurrentRow.Cells(6).Value.ToString())
            cbxThucDon.Text = bus.GetValue("select Gia from NguyenLieu=" + gvBan.CurrentRow.Cells(4).Value.ToString())
            'Dim soluong As Integer = txtSoLuong.Text
            'soluong = gvBan.CurrentRow.Cells(7).Value
            'Dim thucdon As Integer = cbxThucDon.ValueMember = "Gia"


        Catch

        End Try
    End Sub

    Private Sub btnThemBan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemBan.Click
        Dim temp As BanDTO = New BanDTO()
        Dim bus As BanBUS = New BanBUS()
        temp.MaBan = lbMaBan.Text
        temp.MaNhanVien = cbxNhanVienBan.SelectedValue.ToString()
        temp.MaKhachHang = cbxKhachHangBan.SelectedValue.ToString()
        temp.MaThucDon = cbxThucDon.SelectedValue.ToString()
        temp.NgayGio = dtpNgayGioBan.Value.Date
        temp.TinhTrang = cbxTinhTrangBan.SelectedValue.ToString()
        temp.SoLuong = txtSoLuong.Text()
        temp.TongGia = bus.GetValue("select Gia from NguyenLieu")
        bus.Update(temp)
        gvBan_load()
    End Sub

End Class
